<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            /* height: 2000px; */
            margin: 0;
            padding: 0;
        }

        body {
            height: 2000px;
        }


        .first {
            position: fixed;
            top: -80px;
            left: 0;
            width: 100%;
            height: 60px;
            background-color: pink;
            transition: top 0.5s ease;
        }

        .box {
            width: 200px;
            height: 200px;
            background-color: aqua;
            margin-top: 500px;
        }

        button {
            position: fixed;
            bottom: 50px;
            right: 50px;
            width: 100px;
            height: 40px;
        }
    </style>
</head>

<body>
    <div class="first"></div>
    <div class="box">秒杀模块</div>
    <button>回到顶部</button>

    <script>
        const first = document.querySelector('.first')
        const box = document.querySelector('.box')
        const btn = document.querySelector('button')
        window.addEventListener('scroll', function () {
            const n = document.documentElement.scrollTop
            first.style.top = n >= box.offsetTop ? 0 : '-80px'
        })
        btn.addEventListener('click', function () {
            // window.scrollTo(0, 0)
            document.documentElement.scrollTop = 0
        })


    </script>
</body>

</html>